package com.dmp.frame.core.config;

import com.dmp.frame.core.handler.AutoResultReturnHandler;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * @author xufeng
 * @description: 配置自动返回包装类
 * @date 2022-04-20 11:33
 */
@Configuration
public class ResultConfig implements InitializingBean {

    @Autowired
    RequestMappingHandlerAdapter requestMappingHandlerAdapter;


    @Override
    public void afterPropertiesSet() {
        List<HandlerMethodReturnValueHandler> returnValueHandlers = requestMappingHandlerAdapter
                .getReturnValueHandlers();
        List<HandlerMethodReturnValueHandler> list = new ArrayList<>();
        //自定义returnHandler
        list.add(new AutoResultReturnHandler());
        list.addAll(returnValueHandlers);
        requestMappingHandlerAdapter.setReturnValueHandlers(list);
        printSystemUpBanner();

    }

    public static void printSystemUpBanner() {
        String banner = "      _                    __\n" +
                "     | |                  / _|\n" +
                "   __| |_ __ ___  _ __   | |_ _ __ __ _ _ __ ___   ___\n" +
                "  / _` | '_ ` _ \\| '_ \\  |  _| '__/ _` | '_ ` _ \\ / _ \\\n" +
                " | (_| | | | | | | |_) | | | | | | (_| | | | | | |  __/\n" +
                "  \\__,_|_| |_| |_| .__/  |_| |_|  \\__,_|_| |_| |_|\\___|\n" +
                "                 | |\n" +
                "                 |_|\n";
        System.out.println(banner);
    }
}
